import Vue from "vue";
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// 解决重复发路由请求报错现象
let orPush = VueRouter.prototype.push
let orReplace = VueRouter.prototype.replace
VueRouter.prototype.push = function (location, rej, res) {
    if (rej == undefined && res == undefined) {
        orPush.call(this, location, () => { }, () => { })
    } else {
        orPush.call(this, location, rej, res)
    }
}
VueRouter.prototype.replace = function (location, rej, res) {
    if (rej == undefined && res == undefined) {
        orReplace.call(this, location, () => { }, () => { })
    } else {
        orReplace.call(this, location, rej, res)
    }
}
import { routes } from './routes'
import store from 'vuex'
const router =new VueRouter({
    // mode: 'history',
    routes,
    // 跳转路由页面在最上部分
    scrollBehavior() {
        return { y: 0 }
    }
})
// 导航守卫
// router.beforeEach(async(to,from,next)=>{
//     // let user = JSON.parse(localStorage.getItem('user'))
//     let {userInfo} = store.state.userInfo
//     if(userInfo){
//         next()
//       }else{
//         next('/login')
          
//       }
//   })
export default router
